package com.rw.map.model;

/**
 * 记录某个点和node的距离
 */
public class Vertex implements Comparable<Vertex> {
    String id;
    double distance;

    public Vertex(String id, double distance) {
        this.id = id;
        this.distance = distance;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public double getDistance() {
        return distance;
    }

    public void setDistance(double distance) {
        this.distance = distance;
    }


    @Override
    public int compareTo(Vertex o) {
        if (this.distance < o.distance) {
            return -1;
        } else if (this.distance > o.distance) {
            return 1;
        } else {
            return this.id.compareTo(o.id);
        }
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        Vertex other = (Vertex) obj;
        if (distance == 0) {
            if (other.distance != 0) {
                return false;
            }
        } else if (!(distance == other.distance)) {
            return false;
        }
        if (!(id.equals(other.id))) {
            return false;
        }
        return true;
    }

}
